﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../layui/css/layui.css"  media="all">
</head>
<body>

  <div class="layui-fluid">
      <div class="layui-form" >
        <div class="layui-inline">
             <label class="layui-form-label">渠道筛选：</label>
              <div class="layui-input-block">
                <select name="interest" lay-filter="level" id="level">
                  <option value="0">全部</option>
                  <option value="1">A</option>
                  <option value="2">B</option>
                </select>
              </div>
        </div>
        
        <div class="layui-inline">
          
          <div class="layui-inline">
            日期选择：
          </div>
          <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
            <input type="text" class="layui-input" id="date1" style="width:300px;">
          </div>

        </div>
        <div class="layui-inline">
          <button class="layui-btn layui-btn-primary" id="importExcel">导出excel</button>
        </div>
      </div>
      <div class="layui-block">
        <table id="demo" lay-filter="test"></table>
      </div>
  </div>      
</body>
<script src="../layui/layui.all.js"></script>
<script type="text/javascript" src="../../disanfanglogin/vendor/jquery/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../js/linxi.js"></script>
<script type="text/javascript">
  $(document).ready(function(){

    

    Date.prototype.Format = function (fmt) { // author: meizz
      
      var o = {
          "M+": this.getMonth() + 1, // 月份
          "d+": this.getDate(), // 日
          "h+": this.getHours(), // 小时
          "m+": this.getMinutes(), // 分
          "s+": this.getSeconds(), // 秒
          "q+": Math.floor((this.getMonth() + 3) / 3), // 季度
          "S": this.getMilliseconds() // 毫秒
      };
      if (/(y+)/.test(fmt))
          fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
      for (var k in o)
          if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
              return fmt;

    }

    var layer = layui.layer;

    var form = layui.form;

    var table = layui.table;

    var starDate = new Date().Format('yyyy-MM-dd 00:00:00')

    var endDate = new Date().Format('yyyy-MM-dd 23:59:59')

    var filses  =[ //表头
         {field: 'start_date', title: '日期', fixed: 'left',sort: true}
        ,{field: 'title', title: '客户名称',  fixed: 'left'}
        ,{field: '', title: '渠道',  fixed: 'left',templet:function(d){
          if(d['NAME']=='test-lx'){
            return 'B'
          }else if(d['NAME']=='591-lx'){
            return 'A'
          }
        }}
        ,{field: 'link_url', title: '联系方式'}
        
      ]

    linxi.createTable({type:'getABku',starDate:linxi.starDate,endDate:linxi.endDate,ABku:"(\'test-lx\',\'591-lx\')"},"#demo",filses,true)

    linxi.laydate('#date1',function(value, date, endDate){
        console.log(date)
        var table =linxi.table;
        dateRange = value.split(' - ').join("&endDate=")
        table.reload('demo', {
            url: '../api/api.php?type=getABku&starDate='+dateRange +'&ABku='+linxi.getFormSelectLevelSql($('#level').val())
        });
    })



    $('#importExcel').click(function(e){

      

      // dateRange = $('#date1').val().split(' - ').join("&endDate=")
      var layer= linxi.layer;
      //loading层
      var index = layer.load(1, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
      });



      var parseData = {

                        type:'getABku',
                        starDate:$('#date1').val().split(' - ')[0],
                        endDate:$('#date1').val().split(' - ')[1],
                        ABku:linxi.getFormSelectLevelSql($('#level').val())

                      }


      $.get('../api/api.php',parseData,function(data){

                  var res = JSON.parse(data)
                  res['data'] = JSON.stringify(res['data'])
                  res['type']='importExcel'
                  res['tableName']='电话导入模板'
                  res['fields'] = [{field:'start_date',title:'日期'},{field:'NAME',title:'渠道'},{field:'title',title:'客户姓名'},{field:'link_url',title:'手机号'}]
                  
                  $.post('../api/api.php',res,function(data){
                      
                      linxi.download_file(data)

                      layer.close(index)
                  })

      })


    }) 

    linxi.laySelect('level',"demo",{type:"getABku"})

 

  })
</script>
</html>